<template>
    <div>
        <common-title title-name="上传立项信息"></common-title>
        <el-card shadow="never" class="card-box">
            <el-form
                    ref="formRef"
                    :model="form"
                    :rules="rules"
                    label-width="100px">
                <label class="form-title">上传任务通知书文件:</label>
                <el-form-item label="上传文件:" class="m-t20" prop="fileVoList">
                    <FileMinioUpload
                            :restriction="true"
                            :restrictionLimit="9"
                            v-model:files="form.fileVoList"
                    />
                </el-form-item>
<!--                <label class="form-title">上传议题信息:</label>
                <el-form-item label="议题名称:" class="m-t20" prop="meetingName">
                    <el-input v-model="form.meetingName" placeholder="请输入议题名称"></el-input>
                </el-form-item>
                <el-form-item label="议题性质:" prop="meetingNature">
                    <el-select v-model="form.meetingNature" clearable>
                        <el-option value="0" label="三重一大类"></el-option>
                        <el-option value="1" label="非三重一大类"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="会审部门:" prop="reviewDepartment">
                    <el-select v-model="form.reviewDepartment"  multiple collapse-tags class="m-l5" clearable filterable placeholder="请选择会审部门">
                        <el-option v-for="(item,index) in departmentList" :key="index" :label="item.deptName" :value="item.deptId"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="议题简述:" prop="meetingResume">
                    <el-input
                            v-model="form.meetingResume"
                            placeholder="请输入议题简述"
                              :rows="5"
                              type="textarea"></el-input>
                </el-form-item>
                <el-form-item label="议题附件:" prop="subMeetingFiles">
                    <FileMinioUpload
                            :restriction="true"
                            :restrictionLimit="9"
                            v-model:files="form.subMeetingFiles"
                    />
                </el-form-item>
                <label class="form-title">决策会议信息:</label>
                <el-form-item label="会议名称:" class="m-t20" prop="approvalMeetingName">
                    <el-input v-model="form.approvalMeetingName" placeholder="请输入会议名称"></el-input>
                </el-form-item>
                <el-form-item label="申请原因:" prop="applicationCase">
                    <el-input v-model="form.applicationCase" placeholder="请输入申请原因"
                              :rows="5"
                              type="textarea"></el-input>
                </el-form-item>-->
                <el-form-item>
                    <el-button @click="onBack">返回</el-button>
                    <el-button @click="onSubmit()">确认</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script setup>
import {ElForm, ElFormItem, ElCard, ElMessage} from "element-plus";
import {useRouter} from "vue-router";
import FileMinioUpload from "@/components/FileMinioUpload.vue";
import {onMounted, reactive, ref} from "vue";
import {fundManagementApi} from "@/api/businessFinance";
import CommonTitle from "@/components/CommonTitle.vue";
import {projectConfigApi} from "@/api/project";

const router = useRouter();

const getProjectId = router.currentRoute.value.params.id;

const form = reactive({
    projectId:getProjectId,
    fileVoList:[],
    subMeetingFiles:[],
    meetingType:2
});

const rules  = reactive({
    fileVoList: [
        { required: true, message: '请上传任务通知书文件', trigger: 'blur' },
    ],
    meetingName: [
        { required: true, message: '请输入传议题名称', trigger: 'blur' },
    ],
    meetingNature: [
        { required: true, message: '请选择议题性质', trigger: 'change' },
    ],
    reviewDepartment: [
        { required: true, message: '请选择会审部门', trigger: 'change' },
    ],
    meetingResume: [
        { required: true, message: '请输入议题简述', trigger: 'blur' },
    ],
    subMeetingFiles: [
        { required: true, message: '请上传议题附件', trigger: 'change' },
    ],
    approvalMeetingName: [
        { required: true, message: '请输入会议名称', trigger: 'blur' },
    ],
    applicationCase: [
        { required: true, message: '请输入会议申请原因', trigger: 'blur' },
    ],
});

/**
 * 查询部门
 * @type {Ref<UnwrapRef<*[]>>}
 */
const departmentList = ref([]);
const getDepartmentVo = () => {
    fundManagementApi.getDepartmentVo().then(res=>{
        departmentList.value = res.data;
    });
}

const formRef = ref(null);

/**
 * 提交表单
 */
const onSubmit = () => {
    formRef.value.validate((valid, fields) => {
        if (valid) {
            projectConfigApi.updateGovernment(form).then(res=>{
                if(res.code==='200'){
                    ElMessage.success('提交成功!');
                    router.push({path:`/constructionProjectManage/preliminaryProject/index`});
                }else{
                    ElMessage.error('提交失败!');
                }
            });
        } else {
            console.log('error submit!', fields)
        }
    })
}

/**
 * 返回
 */
const onBack = () => {
    router.push({path:`/constructionProjectManage/preliminaryProject/index`});
}

onMounted(()=>{
    getDepartmentVo();
});
</script>

<style lang="scss" scoped>
  .form-title{
    font-size: 16px;
    font-family: SourceHanSansCN-Medium, SourceHanSansCN;
    font-weight: 600;
    color: #1A1A1A;
  }
  .card-box{
    width: 60%;
  }
</style>
